package co.fitstart.coach.dao;

import java.util.List;

import com.demo2do.core.persistence.annotation.Dynamic;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;

import co.fitstart.entity.course.round.CourseRound;
import co.fitstart.entity.course.round.CourseRoundResult;
import co.fitstart.entity.course.round.RoundCoursewareStatus;
import co.fitstart.entity.course.round.RoundStatus;
import co.fitstart.entity.principal.Principal;

/**
 * 
 * @author wangliwang
 *
 */
@Dynamic("hibernate")
public interface CourseRoundDao {

    /**
     * 
     * @param principal
     * @param roundCoursewareStatus
     * @param courseStatus
     * @return
     */
    @Query("FROM CourseRound WHERE disabled = false AND course.experience = false AND courseType in (1,3) AND coach = :coach AND roundCoursewareStatus = :roundCoursewareStatus AND courseStatus IN (:courseStatus)")
    public List<CourseRound> listUnfinish(@Variable("coach") Principal principal, @Variable("roundCoursewareStatus") RoundCoursewareStatus roundCoursewareStatus, @Variable("courseStatus") List<RoundStatus> courseStatus);
    
    /**
     * 
     * @param principal
     * @param roundCoursewareStatus
     * @param courseStatus
     * @return
     */
    @Query("FROM CourseRound WHERE disabled = false AND course.experience = false AND courseType in (1,3) AND coach = :coach AND (roundCoursewareStatus = :roundCoursewareStatus OR courseStatus = :courseStatus)")
    public List<CourseRound> listFinish(@Variable("coach") Principal principal, @Variable("roundCoursewareStatus") RoundCoursewareStatus roundCoursewareStatus, @Variable("courseStatus") RoundStatus courseStatus);
    
    /**
     * 
     * @param principal
     * @param roundCoursewareStatus
     * @param status
     * @return
     */
    @Query("FROM CourseRound WHERE disabled = false AND course.experience = false AND courseType in (1,3) AND coach = :coach AND roundCoursewareStatus = :roundCoursewareStatus AND courseStatus = :status")
    public List<CourseRound> list(@Variable("coach") Principal principal, @Variable("roundCoursewareStatus") RoundCoursewareStatus roundCoursewareStatus, @Variable("status") RoundStatus status);
    
    /**
     * 
     * @param principal
     * @param status
     * @return
     */
    @Query("FROM CourseRound WHERE disabled = false AND course.experience = false AND courseType in (1,3) AND coach = :coach AND courseStatus = :status")
    public List<CourseRound> listCancel(@Variable("coach") Principal principal, @Variable("status") RoundStatus status);
    
    /**
     * @param id
     * @param principal
     * @param roundCoursewareStatus
     * @return
     */
    @Query("FROM CourseRound WHERE id = :id AND coach = :coach AND roundCoursewareStatus = :roundCoursewareStatus AND createTime IS NOT NULL AND disabled = false")
    public CourseRound load(@Variable("id") Long id, @Variable("coach") Principal principal, @Variable("roundCoursewareStatus") RoundCoursewareStatus roundCoursewareStatus);

    /**
     * 
     * @param courseRound
     * @return
     */
    @Query("FROM CourseRoundResult WHERE courseRound = :courseRound")
    public CourseRoundResult loadCourseRoundResult(@Variable("courseRound") CourseRound courseRound);
}
